# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@作者 杨阳
@时间 2018-08-10
@说明 主要用于爬取当天的天气
@注意事项
"""

from urllib.request import urlopen
from bs4 import BeautifulSoup


def get_today_weather():
    """
    通过中国天气官网爬取天气
    地址：http://www.weather.com.cn/weather1d/101010100.shtml
    说明：weather1d表示是当天的 weather表示是查询7天
    :return:
    """
    res_html = urlopen("http://www.weather.com.cn/weather1d/101010100.shtml")
    content = res_html.read().decode('utf-8')

    soup = BeautifulSoup(content, 'html.parser')

    #####################################限行相关##################################
    xianxing = soup.find("div", class_="zs limit")
    xianxing_1 = xianxing.em.find_all('b')[0].string
    xianxing_2 = xianxing.em.find_all('b')[1].string
    print("今日限行:{}和{}".format(xianxing_1, xianxing_2))

    tianqi = soup.find(id='hidden_title').get('value')
    print("今在天气：{}".format(tianqi))

    updatetime = soup.find(id='fc_24h_internal_update_time').get('value')
    print("更新时间:{}".format(updatetime))

    kongqitype = soup.find("div", class_="xyn-icon-bj cur").span.get('title')
    print("空气状况:{}".format(kongqitype))

    diqu = soup.find("div", class_="crumbs fl").a.text
    print("当前城区:{}".format(diqu))


if __name__ == '__main__':
    get_today_weather()
